***JOP Kane, Mason, and Wronski****
***Maintext Figures and Tables -- CCES Survey data***
use "JOP_KMW_CCES.dta" file


*********************correlation of correctly placing groups with political knowledge & interest
	**CCES** **use "JOP_WatP_CCES.dta" file
pwcorr dem_perceptual01 rep_perceptual01 polint, sig star(.05)

**Incorrect group placement
**<2% rate any Dem group as close to Rep Party
tab women_party
tab black_party
tab atheist_party
tab muslim_party
tab hisp_party
tab fem_party
**<7% rated any Rep group as close to Dem Party
tab men_party
tab white_party
tab christ_party

*********************Figure 2: Sentiments Toward Party Coalitions & Party Identification************
reg partyid DemGroups_pfscore GOPgroups_pfscore ///
	dem_perceptual01 rep_perceptual01 ///
	polint age01 educ01 income01 gender ///
	black hisp other_race /// white= baseline
	catholic mormon jewish other_rel no_relig attend01, robust // protestant= baseline

coefplot, drop(_cons) ci(95) xline(0) scheme(plottig) xlabel(-2(.5)2)  ///
coeflabels (DemGroups_pfscore = "{bf: Democratic Coalition Score}" GOPgroups_pfscore = "{bf: Republican Coalition Score}" ///
dem_perceptual01 = "Perceptual Accuracy (Dem Groups)" rep_perceptual01 = "Perceptual Accuracy (Rep Groups)" ///
polint= "Political Interest" age01 = "Age" educ01 = "Education" income01 = "Income" gender = "Female" ///
black = "African-American" hisp = "Hispanic" other_race = "Other Racial Identification" ///
catholic = "Catholic" mormon = "Mormon" jewish = "Jewish" other_rel= "Other Religious Identification" no_relig ="No Religion / No Answer" ///
attend01= "Religiosity") 


* margins across the IQR.  Input the lower and upper bound of the IQR for each party */	
*indicates predicted PID at 25th and 75th percentiles; 
*subtract first from second to determine effect size
**Dem groups 3.07 - 4.32
sum DemGroups_pfscore, d
margins, at(DemGroups_pfscore=(-.711 .582))

**Rep groups 4.15 - 2.95
sum GOPgroups_pfscore, d
margins, at(GOPgroups_pfscore=(-.724 .557))

**predicted values of PID under certain traits
**White, High Warmth for GOP groups, & above average perceptual accuracy
margins if white==1 & GOPgroups_pfscore>=.557 & dem_perceptual01>=.616 ///
	& rep_perceptual01>=.51, at(DemGroups_pfscore=(.582 -.711))
	
	
********************Figure 3: Sentiments Toward Party Coalitions, Perceptual Accuracy, and Party ID************
reg partyid c.DemGroups_pfscore##c.dem_perceptual01 c.GOPgroups_pfscore##c.rep_perceptual01 ///
	polint age01 educ01 income01 gender ///
	black hisp other_race /// white= baseline
	catholic mormon jewish other_rel no_relig attend01, robust // protestant= baseline
	
margins, dydx(DemGroups_pfscore) at (dem_perceptual01=(0(.2)1))

marginsplot, level(95) recastci(rarea) ciopts(fcolor(gs2%35) fintensity(55) lcolor(gs8%75) lpattern(dash)) ///
plotopts(msymbol(T) mcolor(black)) ///
scheme(plotplain)  yline(0) ///
addplot(hist dem_perceptual01,  title( " ") ylabel(-1(.5)1) ytitle("{bf: Conditional Effect of Democratic-Groups Sentiments on PID}", size(small)) ///
xtitle("{bf: Perceptual Accuracy (Democratic Groups)}", size(medsmall)) ///
yaxis(2) yscale(alt axis(2)) percent ///
ylabel(0 "0%" 5 "5%" 10 "10%" 15 "15%" 20 "20%" 25 "25%" 30 "30%", labcolor(black*.9) axis(2)) ///
ytitle("{it: Percent of Sample}", axis(2) orientation(rvertical))  fcolor(white%10) lcolor(black*.5)) ///
legend(off) ///
xsize(6.5) ysize(4.5) graphregion(margin(vsmall)) ///
name(g1,replace)	

margins, dydx(GOPgroups_pfscore) at (rep_perceptual01=(0(.2)1))

marginsplot, level(95) recastci(rarea) ciopts(fcolor(gs2%35) fintensity(55) lcolor(gs8%75) lpattern(dash)) ///
plotopts(msymbol(T) mcolor(black)) ///
scheme(plotplain) yline(0) ///
addplot(hist rep_perceptual01,  title( " ") ylabel(-1(.5)1) ytitle("{bf: Conditional Effect of Republican-Groups Sentiments on PID}", size(small)) ///
xtitle("{bf: Perceptual Accuracy (Republican Groups)}", size(medsmall)) ///
yaxis(2) yscale(alt axis(2)) percent ///
ylabel(0 "0%" 5 "5%" 10 "10%"  15 "15%" 20 "20%" 25 "25%" 30 "30%", labcolor(black*.9) axis(2)) ///
ytitle("{it: Percent of Sample}", axis(2) orientation(rvertical))  fcolor(white%10) lcolor(black*.5)) ///
legend(off) ///
xsize(6.5) ysize(4.5) graphregion(margin(vsmall)) ///
name(g2,replace)

graph combine g1 g2, ycommon iscale(.6) graphregion(margin(tiny))	
	
